/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 言初
 * Date: 2022-11-11
 * Time: 11:54
 */

import java.util.Scanner;

public class Main {

    //实现一个简单的控制台版用户登陆程序,
    // 程序启动提示用户输入用户名密码. 如果用户名密码出错, 使用自定义异常的方式来处理

    private String name="gwj";
    private String password="1234";
    public void Login(String name,String password)
            throws UserNameException,PassWordException{
        if(!this.name.equals(name)){
            System.out.println("用户名错误");
            throw new UserNameException("同志，你的用户名错了！");
        }
        if(!this.password.equals(password)){
            System.out.println("密码错误");
            throw new PassWordException();
        }
        System.out.println("登录成功！");
    }
    public static void main(String[] args) {
        Main main=new Main();
        //输入
        Scanner src=new Scanner(System.in);
        try{
            //输入
            System.out.println("请输入用户名：");
            String name=src.nextLine();
            System.out.println("请输入密码：");
            String password=src.nextLine();
            main.Login(name,password);
        }catch(UserNameException e){
            System.out.println("用户名异常");
            e.printStackTrace();
        }catch(PassWordException e){
            System.out.println("密码异常");
            e.printStackTrace();
        }finally{
            //输入的关闭
            src.close();
        }
    }
}


/*class UserNameException extends Exception {
    public UserNameException(String message) {
        super(message);
    }
}
class PasswordException extends Exception {
    public PasswordException(String message) {
        super(message);
    }
}
public class LogIn {
    private String userName = "admin";
    private String password = "123456";
    public static void loginInfo(String userName, String password)
            throws UserNameException,PasswordException{
        if (!userName.equals(userName)) {
            throw new UserNameException("用户名错误！");
        }
        if (!password.equals(password)) {
            throw new PasswordException("用户名错误！");
        }
        System.out.println("登陆成功");
    }
    public static void main(String[] args) {
        try {
            loginInfo("admin", "123456");
        } catch (UserNameException e) {
            e.printStackTrace();
        } catch (PasswordException e) {
            e.printStackTrace();
        }
    }
}*/

/*class B {
    public int Func() {
        System.out.print("B");
        return 0;
    }
}
class D extends B {
    @Override
    public int Func() {
        System.out.print("D");
        return 0;
    }
}
public class Main {
    public static void main(String[] args) {
        B a = new B();
        B b = new D();
        a.Func();
        b.Func();
    }
}*/

/*class Person {
    public String name;
    public int age;
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("构造方法执行");
    }
    {
        System.out.println("实例代码块执行");
    }
    static {
        System.out.println("静态代码块执行");
    }
}
public class Main {
    public static void main(String[] args) {
        Person person1 = new Person("bit",10);
        System.out.println("============================");
        Person person2 = new Person("gaobo",20);
    }
}*/

/*
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            int z = scanner.nextInt();
            Sub sub = new Sub(x, y, z);
            System.out.println(sub.calculate());
        }
    }

}

class Base {

    private int x;
    private int y;

    public Base(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

}

class Sub extends Base {

    private int z;

    public Sub(int x, int y, int z) {
        //write your code here
        super(x,y);
        this.z=z;
    }

    public int getZ() {
        return z;
    }

    public int calculate() {
        return super.getX() * super.getY() * this.getZ();
    }

}
*/

/*class X{
    Y y=new Y();//1
    public X(){//2
        System.out.print("X");
    }
}
class Y{
    public Y(){//3
        System.out.print("Y");
    }
}
public class Main extends X{
    Y y=new Y();//4
    public Main(){//5
        System.out.print("Z");
    }
    public static void main(String[] args) {
        new Main();
    }
}*/


/*
class Base{
    public Base(String s){
        System.out.print("B");
    }
}

public class Main extends Base{
    public Main (String s) {
        System.out.print("D");
    }
    public static void main(String[] args){
        new Main("C");
    }
}
*/


/*class Base {
    Base() {
        System.out.print("Base");
    }
}

public class Main extends Base {

    public static void main( String[] args ) {
        new Main();//1
        //调用父类无参的构造方法
        new Base();//2
    }
}*/
/*public class Person{

    private String name = "Person";

    int age=0;

}

public class Child extends Main{

    public String grade;

    public static void main(String[] args){

        Person p = new Child();

        System.out.println(p.name);

    }

}*/
/*
class Person {
    public String name;
    public int age;
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("Person：构造方法执行");
    }
    {
        System.out.println("Person：实例代码块执行");
    }
    static {
        System.out.println("Person：静态代码块执行");
    }
}
class Student extends Person{
    public Student(String name,int age) {
        super(name,age);
        System.out.println("Student：构造方法执行");
    }
    {
        System.out.println("Student：实例代码块执行");
    }
    static {
        System.out.println("Student：静态代码块执行");
    }
}
public class Main {
    public static void main(String[] args) {
        Student student1 = new Student("张三",19);
        System.out.println("===========================");
        Student student2 = new Student("gaobo",20);
    }
}
*/


/*Person：静态代码块执行
        Student：静态代码块执行
        Person：实例代码块执行
        Person：构造方法执行
        Student：实例代码块执行
        Student：构造方法执行
        ===========================
        Person：实例代码块执行
        Person：构造方法执行
        Student：实例代码块执行
        Student：构造方法执行*/




